package binaryTree;

import java.util.Stack;

public class PreOrder {
	public static void preOrder(TreeNode root) {
		Stack<TreeNode> s=new Stack<>();
		s.add(root);
		while(!s.isEmpty()) {
			//对头出队列
			TreeNode cur=s.pop();
			System.out.print(cur.val+" ");
			//先入右，再入左
			if(cur.right!=null) {
				s.add(cur.right);
			}
			if(cur.left!=null) {
				s.add(cur.left);
			}
		}
	}
}
